local skel = fk.CreateSkill {
  name = "lb__zhili",
  tags = { Skill.Compulsory }
}

Fk:loadTranslationTable {
  ["lb__zhili"] = "支离",
  --[":lb__zhili"] = "每回合限一次，当你使用伤害牌时，你可以额外成为此牌目标，若所有目标均受到此牌伤害，你摸已损失体力值张牌。",
  --9.18
  [":lb__zhili"] = "每回合限一次，当你使用伤害牌时，你可以额外成为此牌目标，若所有目标均受到此牌伤害，你摸已损失体力值张牌，否则你回复1点体力。",

  ["#lb__zhili"] = "支离：你可以额外成为 %arg 的目标，若所有目标均受到此牌伤害，你摸已损失体力值张牌",

  ["$lb__zhili1"] = "彼岸葬送。",
  ["$lb__zhili2"] = "死兆将至。",
}

skel:addEffect(fk.CardUsing, {
  anim_type = "masochism",
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(skel.name) and player == target
        and player:usedSkillTimes(skel.name) == 0
        and data.card.is_damage_card and not table.contains(data.tos, player)
  end,
  on_cost = function(self, event, target, player, data)
    return player.room:askToSkillInvoke(player,
      { skill_name = skel.name, prompt = "#lb__zhili:::" .. data.card:toLogString() })
  end,
  on_use = function(self, event, target, player, data)
    data:addTarget(player)
    data.extra_data = data.extra_data or {}
    data.extra_data.lb__zhili = player
  end,
})

--[[
skel:addEffect(fk.CardUseFinished, {
  is_delay_effect = true,
  anim_type = "drawcard",
  can_trigger = function(self, event, target, player, data)
    if data.extra_data and data.extra_data.lb__zhili and data.extra_data.lb__zhili == player
    and not player.dead and player:isWounded() and data.damageDealt then
      for _, to in ipairs(data.tos) do
        if data.damageDealt[to] == nil then return end
      end
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    player:drawCards(player:getLostHp(), skel.name)
  end,
})
--]]

skel:addEffect(fk.CardUseFinished, {
  is_delay_effect = true,
  anim_type = "drawcard",
  can_trigger = function(self, event, target, player, data)
    return data.extra_data and data.extra_data.lb__zhili and data.extra_data.lb__zhili == player and not player.dead
    and player:isWounded()
  end,
  on_use = function(self, event, target, player, data)
    if data.damageDealt == nil or table.find(data.tos, function (to)
      return data.damageDealt[to] == nil
    end) then
      player.room:recover {
        who = player,
        num = 1,
        skillName = skel.name,
        recoverBy = player,
      }
    else
      player:drawCards(player:getLostHp(), skel.name)
    end
  end,
})

return skel